/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogUsuario.java
 *
 * Created on 06/07/2011, 03:13:35 PM
 */
package com.igorov.efficientsoft.application.usuarios;

import com.igorov.efficientsoft.business.gestorciudad.GestorCiudad;
import com.igorov.efficientsoft.business.gestordistrito.GestorDistrito;
import com.igorov.efficientsoft.business.gestorusuario.GestorUsuario;
import com.igorov.efficientsoft.business.gestorperfil.GestorPerfil;
import com.igorov.efficientsoft.business.gestorzona.GestorZona;
import com.igorov.efficientsoft.services.CiudadDTO;
import com.igorov.efficientsoft.services.DistritoDTO;
import com.igorov.efficientsoft.services.PerfilDTO;
import com.igorov.efficientsoft.services.UsuarioDTO;
import com.igorov.efficientsoft.services.ZonaDTO;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.swing.DefaultComboBoxModel;
import org.springframework.context.ApplicationContext;

/**
 *
 * @author igorov
 */
public class DialogUsuario extends javax.swing.JDialog {

    /** Creates new form DialogUsuario */
    public DialogUsuario(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    public DialogUsuario(java.awt.Frame parent, boolean modal, ApplicationContext ctx,
                        GestorUsuario gestorUsuario, int idUsuario) {
        super(parent, modal);
        initComponents();
        this.ctx = ctx;
        this.gestorUsuario = gestorUsuario;
        this.idUsuario = idUsuario;
        
        if (idUsuario == 0) {
            setTitle("Nuevo usuario");
        } else{
            setTitle("Editando datos del usuario " + idUsuario);
        }
        
        llenarCmbPerfiles();
        llenarCmbCiudades();
    }
    
    private void llenarCmbPerfiles(){
        DefaultComboBoxModel modelCmbPerfil = new DefaultComboBoxModel();
        modelCmbPerfil.addElement("Elegir ...");
        
        gestorPerfil = (GestorPerfil) ctx.getBean("gestorPerfil");
        List<PerfilDTO> perfilDTOs = gestorPerfil.getAll();
        
        for (Iterator<PerfilDTO> it = perfilDTOs.iterator(); it.hasNext();) {
            PerfilDTO perfilDTO = it.next();
            modelCmbPerfil.addElement(perfilDTO.getNombre());
        }
        this.cmbPerfil.setModel(modelCmbPerfil);
    }
    
    private void llenarCmbCiudades(){
        DefaultComboBoxModel modelCmbCiudad = new DefaultComboBoxModel();
        modelCmbCiudad.addElement("Elegir ...");
        
        gestorCiudad = (GestorCiudad) ctx.getBean("gestorCiudad");
        List<CiudadDTO> ciudadDTOs = gestorCiudad.getAll();
        
        for (Iterator<CiudadDTO> it = ciudadDTOs.iterator(); it.hasNext();) {
            CiudadDTO ciudadDTO = it.next();
            modelCmbCiudad.addElement(ciudadDTO.getNombre());
        }
        
        this.cmbCiudad.setModel(modelCmbCiudad);
    }
    
    private void llenarCmbDistritos(int idCiudad){
        DefaultComboBoxModel modelCmbDistritos = new DefaultComboBoxModel();
        modelCmbDistritos.addElement("Elegir ...");
        mapaDistritos = new HashMap<Integer, Integer>();
        
        gestorDistrito = (GestorDistrito) ctx.getBean("gestorDistrito");
        List<DistritoDTO> distritoDTOs = gestorDistrito.getAllByCiudad(idCiudad);
        
        for (Iterator<DistritoDTO> it = distritoDTOs.iterator(); it.hasNext();) {
            DistritoDTO distritoDTO = it.next();
            modelCmbDistritos.addElement(distritoDTO.getNombre());
//            System.out.println("Mapa: " + (modelCmbDistritos.getSize() - 1)+","+distritoDTO.getCodigo());;
            mapaDistritos.put(modelCmbDistritos.getSize() - 1, distritoDTO.getCodigo());
        }
        
        this.cmbDistrito.setModel(modelCmbDistritos);
    }
    
    private void limpiarCmbDistritos(){
        DefaultComboBoxModel modelCmbDistritos = new DefaultComboBoxModel();
        this.cmbDistrito.setModel(modelCmbDistritos);
        mapaDistritos = new HashMap<Integer, Integer>();
    }
    
    private void llenarCmbZonas(int idDistrito){
        DefaultComboBoxModel modelCmbZonas = new DefaultComboBoxModel();
        mapaZonas = new HashMap<Integer, Integer>();
        
        gestorZona = (GestorZona) ctx.getBean("gestorZona");
        List<ZonaDTO> zonaDTOs = gestorZona.getAllByDistrito(idDistrito);
        
        System.out.println("cantidad de zonas: " + zonaDTOs.size());
        
        for (Iterator<ZonaDTO> it = zonaDTOs.iterator(); it.hasNext();) {
            ZonaDTO zonaDTO = it.next();
            modelCmbZonas.addElement(zonaDTO.getNombre());
            mapaZonas.put(modelCmbZonas.getSize(), zonaDTO.getCodigo());
        }
        
        this.cmbZona.setModel(modelCmbZonas);
    }
    
    private void limpiarCmbZonas(){
        DefaultComboBoxModel modelCmbZonas = new DefaultComboBoxModel();
        this.cmbZona.setModel(modelCmbZonas);
        mapaZonas = new HashMap<Integer, Integer>();
    }
    
    private void guardarUsuario(){
        UsuarioDTO usuarioDTO = new UsuarioDTO();
        usuarioDTO.setCodigo(idUsuario);
        usuarioDTO.setNombre(txtNombre.getText().trim());
        usuarioDTO.setApellido(txtApellidos.getText().trim());
        usuarioDTO.setDireccion(txtDireccion.getText().trim());
        usuarioDTO.setDni(txtDNI.getText().trim());
        usuarioDTO.setEstado(true);
        usuarioDTO.setPassword(txtPassword.getText());
        usuarioDTO.setTelefono(txtTelefono.getText());
        usuarioDTO.setIdZona(mapaZonas.get(cmbZona.getSelectedIndex() + 1));
        
        PerfilDTO perfilDTO = new PerfilDTO();
        
        perfilDTO.setCodigo(gestorPerfil.getIdAtIndex(cmbPerfil.getSelectedIndex() - 1));
        
        usuarioDTO.setPerfilDTO(perfilDTO);
        
//        System.out.println("Guardando usuario");
//        System.out.println("id zona" + usuarioDTO.getIdZona());
//        System.out.println("id perfil" + usuarioDTO.getPerfilDTO().getCodigo());

        gestorUsuario.saveOrUpdate(usuarioDTO);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellidos = new javax.swing.JTextField();
        txtDNI = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        txtDireccion = new javax.swing.JTextField();
        cmbPerfil = new javax.swing.JComboBox();
        cmbCiudad = new javax.swing.JComboBox();
        cmbDistrito = new javax.swing.JComboBox();
        cmbZona = new javax.swing.JComboBox();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.igorov.efficientsoft.application.desktopapplication.EfficientSoftApp.class).getContext().getResourceMap(DialogUsuario.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        txtNombre.setText(resourceMap.getString("txtNombre.text")); // NOI18N
        txtNombre.setName("txtNombre"); // NOI18N

        txtApellidos.setName("txtApellidos"); // NOI18N

        txtDNI.setName("txtDNI"); // NOI18N

        txtTelefono.setName("txtTelefono"); // NOI18N

        txtDireccion.setName("txtDireccion"); // NOI18N

        cmbPerfil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbPerfil.setName("cmbPerfil"); // NOI18N

        cmbCiudad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbCiudad.setName("cmbCiudad"); // NOI18N
        cmbCiudad.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbCiudadItemStateChanged(evt);
            }
        });
        cmbCiudad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbCiudadActionPerformed(evt);
            }
        });

        cmbDistrito.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Elegir..." }));
        cmbDistrito.setName("cmbDistrito"); // NOI18N
        cmbDistrito.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbDistritoItemStateChanged(evt);
            }
        });

        cmbZona.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Elegir..." }));
        cmbZona.setName("cmbZona"); // NOI18N

        btnAceptar.setText(resourceMap.getString("btnAceptar.text")); // NOI18N
        btnAceptar.setName("btnAceptar"); // NOI18N
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnCancelar.setText(resourceMap.getString("btnCancelar.text")); // NOI18N
        btnCancelar.setName("btnCancelar"); // NOI18N
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        txtPassword.setText(resourceMap.getString("txtPassword.text")); // NOI18N
        txtPassword.setName("txtPassword"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(cmbZona, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(cmbCiudad, javax.swing.GroupLayout.Alignment.LEADING, 0, 119, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addGap(3, 3, 3)
                                        .addComponent(cmbDistrito, 0, 200, Short.MAX_VALUE))
                                    .addComponent(txtDireccion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtDNI, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                                            .addComponent(cmbPerfil, javax.swing.GroupLayout.Alignment.TRAILING, 0, 168, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel4))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtTelefono)
                                            .addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)))
                                    .addComponent(txtApellidos, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)))
                            .addComponent(jLabel7)
                            .addComponent(jLabel9)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(147, 147, 147)
                        .addComponent(btnAceptar)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtDNI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(cmbPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cmbCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)
                        .addComponent(cmbDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cmbZona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnAceptar))
                .addGap(26, 26, 26))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbCiudadItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbCiudadItemStateChanged
        // TODO add your handling code here:
        if (cmbCiudad.getSelectedIndex() != 0) {
            llenarCmbDistritos(gestorCiudad.getIdAtIndex(cmbCiudad.getSelectedIndex() - 1));
        } else {
            limpiarCmbDistritos();
        }
        limpiarCmbZonas();
    }//GEN-LAST:event_cmbCiudadItemStateChanged

    private void cmbCiudadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbCiudadActionPerformed
        // TODO add your handling code here:
//        gestorDistrito = (GestorDistrito) ctx.getBean("gestorDistrito");
//        List<DistritoDTO> distritoDTOs = gestorDistrito.getAll();
    }//GEN-LAST:event_cmbCiudadActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void cmbDistritoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbDistritoItemStateChanged
        // TODO add your handling code here:
        if (cmbDistrito.getSelectedIndex() != 0) {
            System.out.println("Llenando zonas con id distrito: "+mapaDistritos.get(cmbDistrito.getSelectedIndex()));
            llenarCmbZonas(mapaDistritos.get(cmbDistrito.getSelectedIndex()));
        } else {
            limpiarCmbZonas();
        }
    }//GEN-LAST:event_cmbDistritoItemStateChanged

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:
        guardarUsuario();
        this.setVisible(false);
    }//GEN-LAST:event_btnAceptarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                DialogUsuario dialog = new DialogUsuario(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cmbCiudad;
    private javax.swing.JComboBox cmbDistrito;
    private javax.swing.JComboBox cmbPerfil;
    private javax.swing.JComboBox cmbZona;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtApellidos;
    private javax.swing.JTextField txtDNI;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtPassword;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables
    private ApplicationContext ctx;
    private GestorUsuario gestorUsuario;
    private GestorPerfil gestorPerfil;
    private GestorCiudad gestorCiudad;
    private GestorDistrito gestorDistrito;
    private GestorZona gestorZona;
    private Map<Integer, Integer> mapaDistritos;
    private Map<Integer, Integer> mapaZonas;
    private int idUsuario;
}
